package com.example.demo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
//import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.domain.po.UserEntity;
import com.example.demo.service.UserService;
import com.example.demo.utils.R;
@CrossOrigin
@RestController
@RequestMapping("/user")
public class UserController {	
	@Autowired
	private UserService userService;
	@PostMapping("/getusers")
    public R getUsers() {
        List<UserEntity> entitys = userService.getUsers();
        return R.success(entitys);
    }
	@PostMapping("/updateuser")
    public R updateUser(@RequestBody UserEntity userEntity) {
        boolean yn = userService.updateUser(userEntity);
        String str;
        if(yn)
        	str = "update success";
        else str = "update error";
        
        return R.success(str);
    }
	@PostMapping("/deleteuser")
    public R deleteUser(@RequestBody UserEntity userEntity) {
        int x = userService.deleteUser(userEntity);
        String 	str = "update success";       
        
        return R.success(str);
    }
}
